package com.glela.packet.service.impl;

import com.glela.domain.vo.RedPacketShareHistVo;
import com.glela.packet.mapper.RedPacketShareHistBizMapper;
import com.glela.packet.mapper.RedPacketShareHistMapper;
import com.glela.packet.model.RedPacketShareHist;
import com.glela.packet.service.RedPacketShareHistService;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

@Service("redPacketShareHistService")
public class RedPacketShareHistServiceImpl implements RedPacketShareHistService {

  @Autowired
  private RedPacketShareHistMapper redPacketShareHistMapper;
  @Autowired
  private RedPacketShareHistBizMapper redPacketShareHistBizMapper;
 
  @Override
  public RedPacketShareHist getRedPacketShareHistById(int id) {
    return redPacketShareHistMapper.selectByPrimaryKey(id);
  }

  @Override
  public boolean saveRedPacketShareHist(RedPacketShareHist redPacketShareHist) {
    return redPacketShareHistMapper.insertSelective(redPacketShareHist) > 0;
  }

  @Override
  public RedPacketShareHist getRedPacketShareHisByShareUrl(String shareUrl) {
    return redPacketShareHistBizMapper.getByShareUrl(shareUrl);
  }

  @Override
  public boolean updateRedPacketShareHist(RedPacketShareHist redPacketShareHist) {
    return redPacketShareHistMapper.updateByPrimaryKeySelective(redPacketShareHist) > 0;
  }

  @Override
  public boolean batchUpdateRedPacketShareHist(List<RedPacketShareHist> list) {
    if (CollectionUtils.isEmpty(list)){
      return false;
    }
    return redPacketShareHistBizMapper.batchUpdate(list) > 0;
  }

  @Override
	public int queryShareTimes(Long userId) {
		// TODO Auto-generated method stub
		return redPacketShareHistBizMapper.queryShareTimes(userId);
	}

	@Override
	public BigDecimal querySumAmount(Long userId) {
		// TODO Auto-generated method stub
		BigDecimal result = redPacketShareHistBizMapper.querySumAmount(userId);
		if(null == result){
			result = BigDecimal.ZERO;
		}
		return result;
	}

	@Override
	public List<RedPacketShareHistVo> showRedPacketShareLists(Long userId) {
		// TODO Auto-generated method stub
		return redPacketShareHistBizMapper.showRedPacketShareLists(userId);
	}
}
